import {View, Text, Button, StyleSheet, Image} from 'react-native';
import React, {useRef, useState} from 'react';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import Geolocation from '@react-native-community/geolocation';
// import {
//   useCameraPermission,
//   useCameraDevice,
//   Camera,
// } from 'react-native-vision-camera';
// import {CameraRoll} from '@react-native-camera-roll/camera-roll';
export default function About() {
  const camera = useRef(null);
  const insets = useSafeAreaInsets();
  // const {hasPermission, requestPermission} = useCameraPermission();
  // const device = useCameraDevice('back');
  const [uri, setUri] = useState('');

  // if (!hasPermission) {
  //   return (
  //     <View>
  //       <Text>没有相机权限</Text>
  //       <Button onPress={requestPermission} title="请求相机权限" />
  //     </View>
  //   );
  // }

  const handlePress = () => {
    Geolocation.getCurrentPosition(info => console.log(info));
  };

  const handleClick = async () => {
    console.log(12313);

    // const photo = await camera.current.takePhoto();
    // console.log('photo', photo);
    // const result = await fetch(`file://${photo.path}`);
    // const data = await result.blob();
    // console.log('data', data);
    // await CameraRoll.saveAsset(`file://${photo.path}`, {
    //   type: 'photo',
    // });

    // console.log('保存成功');
    // setUri(data);
  };

  return (
    <View
      style={[
        styles.container,
        {
          paddingTop: insets.top,
          paddingBottom: insets.bottom,
        },
      ]}>
      {/* <Camera
        style={styles.camera}
        androidPreviewViewType="texture-view"
        ref={camera}
        device={device}
        isActive={true}
        photo={true}
      /> */}
      {uri && <Image style={styles.img} source={uri} />}
      <Button onPress={handlePress} title="获取当前位置" />
      <Button onPress={handleClick} title="拍照" />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  camera: {
    flex: 1,
  },
  img: {
    width: 200,
    height: 200,
  },
});
